// api进行统一管理
import requests from './request'
// 引入mockRequest
import mockRequests from './mockRequest'
// 三级联动接口
// 发送axios请求返回promise对象
export const reqCategoryList = () => {
    // 不写return会返回undifined
    return requests({
        url: 'product/getBaseCategoryList',
        method: 'get'
    })
}

// 发送请求，获取banner轮播图数据
export const reqGetBannerList = () => {
    return mockRequests.get('/banner')
}

// 获取floor的数据
export const reqGetFloorList = () => {
    return mockRequests.get('/floor')
}

// 获取搜索页面的数据
// 当前这个接口需要向服务器传递一个默认参数（至少是一个空对象）
export const reqGetSearchList = (params) => {
    return requests({
        url: '/list',
        method: 'post',
        data: params
    })
}

// 获取详情页数据
export const reqGetDetailData = (skuId) => {
    return requests.get(`/item/${skuId}`)
}

// 将用户选择的商品添加到服务器中保存（或者是更新某个产品的数量）
export const reqPostCartorUpdate = (skuId, skuNum) => {
    return requests.post(`/cart/addToCart/${ skuId }/${ skuNum }`)
}

// 获取购物车列表
export const reqGetShopCartList = ()=>{
    return requests.get('/cart/cartList')
}

// 删除购物车的某个商品
export const reqDeleteGood = (skuId)=>{
    return requests.delete(`/cart/deleteCart/${skuId}`)
}

//切换商品的选择状态
export const reqSwitchStatus = (skuId,isChecked)=>{
    return requests.get(`/cart/checkCart/${skuId}/${isChecked}`)
}

//获取验证码
export const reqGetCode = (phone)=>{
    return requests.get(`/user/passport/sendCode/${phone}`)
}

// 完成注册
export const reqFinishRegister = (params)=>{
    return requests({
        url:'/user/passport/register',
        method:'post',
        data:params
    })
}

//提交信息进行登录
export const reqUserLogin = (data)=>{
   return requests({
       url:'/user/passport/login',
       method:'post',
       data
   })
}

// 通过token令牌获取用户信息
export const  reqGetUserInfo = ()=>{
    return requests.get('/user/passport/auth/getUserInfo')
}

// 退出登录
export const reqUserLogout = ()=>{
    return requests.get('/user/passport/logout')
}

// 获取用户地址信息
export const reqGetUserAddress = ()=>{
     return requests.get('/user/userAddress/auth/findUserAddressList')
}

// 获取订单交易页信息

export const reqGetTradeDetail = ()=>{
    return requests.get('/order/auth/trade')
}

// 提交订单
export const reqSubmitOrder = (tradeNo,params)=>{
    return requests({
        url:`/order/auth/submitOrder?tradeNo=${tradeNo}`,
        method:'post',
        data:params
    })
}

//通过订单号获取订单信息
export const reqGetOrderInfo = (orderId)=>{
    return requests.get(`/payment/weixin/createNative/${orderId}`)
}

// 查询订单支付状态
export const reqGetOrderStatus = (orderId)=>{
    return requests.get(`/payment/weixin/queryPayStatus/${orderId}`)
}

// 获取我的订单列表
export const reqGetMyOrderList = (page,limit)=>{
    return requests.get(`/order/auth/${page}/${limit}`)
}